package ai.plantdata.Structural.mode.FlyweightPattern.factorys;

import ai.plantdata.Structural.mode.FlyweightPattern.interfaces.Shape;
import ai.plantdata.Structural.mode.FlyweightPattern.interfaces.impl.Circle;

import java.util.HashMap;

/**
 * @Author: WangHui
 * @Date: 2020/12/21 16:41
 * @Description:
 */
public class ShapeFactory {
    private static final HashMap<String, Shape> CIRCLE_MAP = new HashMap<String, Shape>();

    public static Shape getCircle(String color){
        Circle circle = (Circle) CIRCLE_MAP.get(color);

        if(circle == null){
            circle = new Circle(color);
            CIRCLE_MAP.put(color,circle);
            System.out.println("Creating circle of color : "+color);
        }
        return circle;
    }
}
